package medium;

/**
 * 3115. 质数的最大距离
 * 创建时间：2024/7/2 上午11:05
 */
public class 质数的最大距离_3115 {
    static int n = 100;
    static boolean[] flag = new boolean[n+1];
    static {
        flag[0] = flag[1] = true;
        for (int i = 2; i <= n; i++) {
           if (!flag[i] && i * i <= n) {
               for (int j = i * i; j <= n; j += i) {
                   flag[j] = true;
               }
           }
        }
    }

    public int maximumPrimeDifference(int[] nums) {
        int l = 0, r = 0;
        for (int i = 0; i < nums.length; i++) {
            if (!flag[nums[i]]) {
                l = i;
                break;
            }
        }
        for (int i = nums.length - 1; i >= 0; i--) {
            if (!flag[nums[i]]) {
                r = i;
                break;
            }
        }
        return  r - l;
    }
}
